package photobox.manage

import grails.converters.JSON
import photobox.BaseController
import photobox.exception.NotFoundException
import photobox.photo.PhotoPaper
import photobox.utils.ParamUtils
import photobox.utils.ResultUtil



class MngPhotoPaperController extends BaseController {
    def  photoPaperService

    def index() {}

    def list() {
        def searchParams = ParamUtils.parseFilter(params.filters)
        def pageParams = ParamUtils.parsePage(params)
        def sortParams = ParamUtils.parseSort(params,
                ["id", "name", "origin", "description"], [sort: 'id', order: "desc"])

        def userRs = photoPaperService.list(searchParams, pageParams, sortParams)
        render ResultUtil.pageResults(userRs.rs, userRs.total, pageParams,
                [id: 'id', name: 'name', origin:'origin' , description:'description']) as JSON
    }

    def create() {

    }

    def save() {
        photoPaperService.createPhotoPaper(params)
        render([error: 0, message: "添加纸张信息完成"] as JSON)
    }

    def edit() {
        def photoPaper = PhotoPaper.get(params.id)
        [photoPaper: photoPaper]
    }

    def update() {
        photoPaperService.updatePhotoPaper(params)
        render([error: 0, message: "更新纸张信息完成"] as JSON)
    }

    def delete() {
        photoPaperService.deletePhotoPaper(params)
        render([error:0, message: "删除纸张信息完成"] as JSON)
    }


}
